/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-08 15:07:44
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.bp.controller;

import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.Pattern;

import cn.zlg.common.springmvc.validate.constraints.NotNull;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorDto;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorQueryBean;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorStaffBean;
import com.joysuch.wwyt.bp.entity.contractor.BpContractorStaff;
import com.joysuch.wwyt.bp.service.BpContractorStaffService;
import com.joysuch.wwyt.core.bean.BatchUploadResult;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 承包商人员管理
 */
@RestController
@RequestMapping("/bp/contractor/staff")
@Api(tags = "承包商人员管理")
public class BpContractorStaffController {

    @Autowired
    private BpContractorStaffService bpContractorStaffService;

    @PostMapping("save")
    @ApiOperation("新增/修改")
    @RequiresPermissions("bp:contractor:staff:save")
    public ResultBean save(@Valid @RequestBody BpContractorStaffBean bean) {
        return bpContractorStaffService.save(bean);
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询", response = BpContractorDto.class)
    public ResultBean page(BpContractorQueryBean bean) {
        return bpContractorStaffService.page(bean);
    }

    @GetMapping("nullify")
    @ApiOperation("作废")
    @RequiresPermissions("bp:contractor:staff:nullify")
    public ResultBean delete(Long id) {
        return bpContractorStaffService.nullify(id);
    }

    @GetMapping("get")
    @ApiOperation(value = "单体查询", response = BpContractorStaffBean.class)
    public ResultBean getById(Long id) {
        return bpContractorStaffService.get(id);
    }

    @PostMapping("locate-sync-user/{flag}")
    @ApiOperation("人员在岗在位-同步承包商人员")
    @ApiImplicitParam(name = "flag", value = "1 同步所有人员; 0 同步部分人员", paramType = "path", required = true)
    @RequiresPermissions("bp:contractor:staff:locate-sync-user")
    public ResultBean locateSyncUser(@PathVariable Integer flag, @RequestBody List<Long> userIds) {
        return bpContractorStaffService.locateSyncUser(flag, userIds);
    }

    @GetMapping("editAlarmTemplate")
    @ApiOperation("添加承包商人员报警模板")
    public ResultBean editAlarmTemplate(Long staffId, Long templateId, String templateName) {
        BpContractorStaff staff = bpContractorStaffService.editAlarmTemplate(staffId, templateId, templateName);
        return ResultBean.success(staff.getId());
    }

    @RequestMapping("batch-upload-id-image")
    @ApiOperation("批量导入证件照片")
    @ResponseBody
    public Object batchUploadCertImages(MultipartFile file,
            @Valid @NotNull(field = "匹配类型") @Pattern(regexp = "name|sn|code") String type) {
        BatchUploadResult result = bpContractorStaffService.batchUploadIdImages(file, type);
        return ResultBean.success(result);
    }
}
